/*
 * @Author: 杨剑兵
 * @Date: 2020-07-22 18:01:54
 * @LastEditTime: 2020-07-30 14:01:42
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \dashboard\src\utils\app.js
 */

/**
 * @description: 地图弹出框
 * @param {type} title
 * @param {type} content
 * @return:
 */

export function createInfoWindow(title, content, map, type) {
  let img = ''
  let topClass = ''
  let middleClass = ''
  if (type === 0) {
    img = require('@/assets/img/map/up1.png')
    topClass = 'info-top info-top-one'
    middleClass = 'info-middle info-middle-one'
  } else {
    img = require('@/assets/img/map/up2.png')
    topClass = 'info-top info-top-two'
    middleClass = 'info-middle info-middle-two'
  }
  const info = document.createElement('div')
  // info.className = 'custom-info input-card content-window-card'
  info.className = 'input-card content-window-card'
  // 可以通过下面的方式修改自定义窗体的宽高
  info.style.width = "400px";
  // 定义顶部标题
  const top = document.createElement('div')
  const titleD = document.createElement('div')
  const closeX = document.createElement('div')
  top.style.position = 'relative'
  top.style.right = '45px'
  top.className = topClass
  titleD.innerHTML = title
  closeX.innerHTML = 'X'
  closeX.className = 'close'
  closeX.onclick = () => {
    map.clearInfoWindow()
  }
  top.appendChild(titleD)
  top.appendChild(closeX)
  info.appendChild(top)

  // 定义中部内容
  const middle = document.createElement('div')
  middle.style.position = 'relative'
  middle.style.top = '0px'
  middle.style.right = '45px'
  middle.style.height = '200px'
  middle.className = middleClass
  middle.innerHTML = content
  info.appendChild(middle)

  // 定义底部内容
  const bottom = document.createElement('div')
  bottom.className = 'info-bottom'
  bottom.style.position = 'relative'
  bottom.style.top = '-1px'
  bottom.style.right = '45px'
  bottom.style.margin = '0 auto'
  const sharp = document.createElement('img')
  sharp.src = img
  bottom.appendChild(sharp)
  info.appendChild(bottom)
  return info
}

export function formatNumber(n) {
  var b = parseInt(n).toString()
  var a = ''
  if (b.indexOf('-') === 0) {
    b = b.slice(1)
    a = '-'
  }
  var len = b.length
  if (len <= 3) {
    return b
  }
  var r = len % 3
  return (
    a +
    (r > 0
      ? b.slice(0, r) +
        ',' +
        b
          .slice(r, len)
          .match(/\d{3}/g)
          .join(',')
      : b
          .slice(r, len)
          .match(/\d{3}/g)
          .join(','))
  )
}
